package com.ibangnuo.manage.service;

import com.ibangnuo.framework.domain.AdminEntity;
import com.ibangnuo.framework.domain.request.AdminEntityQueryPageRequest;
import com.ibangnuo.framework.model.response.CommonCode;
import com.ibangnuo.framework.model.response.QueryResponseResult;
import com.ibangnuo.framework.model.response.QueryResult;
import com.ibangnuo.manage.dao.AdminEntityMapper;
import com.ibangnuo.manage.dao.AdminEntityRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.*;
import org.springframework.stereotype.Service;
import org.apache.commons.lang3.StringUtils;

/**
 * @Author: wwy
 * @Date: 2019-12-18 17:21
 */
@Service
public class AdminEntityService {
    @Autowired
    private AdminEntityRepository adminEntityRepository;
    @Autowired
    private AdminEntityMapper adminEntityMapper;
    /**
     * 分页查询普通员工
     * @param page
     * @param size
     * @param adminEntityQueryPageRequest
     * @return
     */
    public QueryResponseResult findList(int page, int size, AdminEntityQueryPageRequest adminEntityQueryPageRequest){
        if(adminEntityQueryPageRequest == null){
            adminEntityQueryPageRequest = new AdminEntityQueryPageRequest();
        }

        //自定义条件查询
//        ExampleMatcher matcher = ExampleMatcher.matching()
//                .withMatcher("pageAliase",ExampleMatcher.GenericPropertyMatchers.contains())//包含
//                .withMatcher("pageStatus",ExampleMatcher.GenericPropertyMatchers.exact());//准确的
//        AdminEntity adminEntity = new AdminEntity();
//        Example<AdminEntity> example = Example.of(AdminEntity,matcher);
        if(page <= 0){
            page = 1;
        }
        page = page - 1;
        if(size<=0){
            size = 20;
        }
        Pageable pageable = PageRequest.of(page,size);
        Page<AdminEntity> all = adminEntityRepository.findAll(pageable);
        QueryResult<AdminEntity> queryResult = new QueryResult();
        queryResult.setList(all.getContent());
        queryResult.setTotal(all.getTotalElements());
        return new QueryResponseResult(CommonCode.SUCCESS,queryResult);
    }
}
